﻿using System;
using HttpApiGateway;
using HttpApiGateway.Model;
using RpcClient;
using RpcHelper.Validate;
using Wedonek.RpcStore.Gateway.Interface;
using Wedonek.RpcStore.Gateway.Model;
using Wedonek.RpcStore.Service.Model;

namespace Wedonek.RpcStore.Gateway.Controller
{
    /// <summary>
    /// 事务
    /// </summary>
    internal class TransactionController : ApiController
    {
        private readonly ITransactionService _Service = null;
        public TransactionController(ITransactionService service)
        {
            this._Service = service;
        }
        /// <summary>
        /// 获取事务详细
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public TransactionInfo Get([NullValidate("rpc.transaction.id.null")] Guid id)
        {
            return this._Service.Get(id);
        }
        /// <summary>
        /// 获取事务节点
        /// </summary>
        /// <param name="rootId"></param>
        /// <returns></returns>
        public TransactionDatum[] GetTranNode([NullValidate("rpc.transaction.id.null")] Guid rootId)
        {
            return this._Service.GetTranNode(rootId);
        }
        /// <summary>
        /// 查询根事务
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public PagingResult<TransactionDatum> QueryRoot(PagingParam<RootQueryParam> param)
        {
            TransactionDatum[] list = this._Service.QueryRoot(param.Param, param.ToBasicPaging(), out long count);
            return new PagingResult<TransactionDatum>(list, count);
        }
        /// <summary>
        /// 查询事务树
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public PagingResult<TransactionTree> QueryTree(PagingParam<RootQueryParam> param)
        {
            TransactionTree[] list = this._Service.QueryTree(param.Param, param.ToBasicPaging(), out long count);
            return new PagingResult<TransactionTree>(list, count);
        }
    }
}
